package com.dzxcqmxm.servlet.photo;

import com.dzxcqmxm.Dao.AlbumDao;
import com.dzxcqmxm.Dao.PhotoDao;
import com.dzxcqmxm.Dao.impl.AlbumDaoImpl;
import com.dzxcqmxm.Dao.impl.PhotoDaoImpl;
import com.dzxcqmxm.JB.Album;
import com.dzxcqmxm.JB.Photo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Payboi
 * @create 2022/6/4-18:48
 * @FileName photoFindByNameAndPhotoBaoMiServlet
 * @Description
 */
@WebServlet("/photoFindByNameAndPhotoBaoMiServlet")
public class photoFindByNameAndPhotoBaoMiServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PhotoDao photoDao = new PhotoDaoImpl();
        Photo photo = new Photo();
        
        ArrayList<Photo> photoArrayList = new ArrayList<Photo>();
        /**
         * 获取查询公开照片的那个表单的提交的照片名
         */
        photo.setPhotoName(new String(request.getParameter("PhotoName" ).getBytes("iso-8859-1"),"UTF-8"));
        System.out.println("打印一下是否拿到了公开照片的名字"+photo.getPhotoName());

        try {
            photoArrayList = photoDao.photoFindByNameAndPhotoBaoMi(photo.getPhotoName(),"0");
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("打印一下处理之后的查询保密页面的photoArrayList"+photoArrayList);

        //session会话对象可以数据共享于一次会话
        request.getSession().setAttribute("photoArrayList", photoArrayList);

        System.out.println("验证一下我刚设定好的session对象："+request.getSession().getAttribute("photoArrayList"));
        //request.getSession().setAttribute("XTXCName", XTXCName);

        response.sendRedirect("/dzxc/YongHu/YongHuShouYe1.jsp");

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            doPost(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }
}
